package com.fulihui.cloud.plugin.model;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Map;

/**
 * Created by fulihui on 2018/1/6.
 */
public class ShardingRule
{
    private String ip;

    private int port;

    private String userName;

    private String passWord;

    private String dataBase;

    private int dataBaseCount;

    private Map<String, Integer> tables = Maps.newHashMap();

    private String driverName;

    public String getIp()
    {
        return ip;
    }

    public void setIp(String ip)
    {
        this.ip = ip;
    }

    public int getPort()
    {
        return port;
    }

    public void setPort(int port)
    {
        this.port = port;
    }

    public String getUserName()
    {
        return userName;
    }

    public void setUserName(String userName)
    {
        this.userName = userName;
    }

    public String getPassWord()
    {
        return passWord;
    }

    public void setPassWord(String passWord)
    {
        this.passWord = passWord;
    }

    public String getDataBase()
    {
        return dataBase;
    }

    public void setDataBase(String dataBase)
    {
        this.dataBase = dataBase;
    }

    public int getDataBaseCount()
    {
        return dataBaseCount;
    }

    public Map<String, Integer> getTables()
    {
        return tables;
    }

    public void setTables(Map<String, Integer> tables)
    {
        this.tables = tables;
    }

    public void setDataBaseCount(int dataBaseCount)
    {
        this.dataBaseCount = dataBaseCount;
    }

    public String getDriverName()
    {
        return driverName;
    }

    public void setDriverName(String driverName)
    {
        this.driverName = driverName;
    }

    @Override
    public String toString()
    {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    public static class ShardingRuleBuilder
    {
        private ShardingRule shardingRule;

        public ShardingRuleBuilder()
        {
            shardingRule = new ShardingRule();
        }

        public ShardingRuleBuilder addIp(String ip)
        {
            shardingRule.setIp(ip);
            return this;
        }

        public ShardingRuleBuilder addPort(int port)
        {
            shardingRule.setPort(port);
            return this;
        }

        public ShardingRuleBuilder addUserName(String userName)
        {
            shardingRule.setUserName(userName);
            return this;
        }

        public ShardingRuleBuilder addPassWord(String passWord)
        {
            shardingRule.setPassWord(passWord);
            return this;
        }

        public ShardingRuleBuilder addDataBase(String dataBase)
        {
            shardingRule.setDataBase(dataBase);
            return this;
        }

        public ShardingRuleBuilder addDataBaseCount(int dataBaseCount)
        {
            shardingRule.setDataBaseCount(dataBaseCount);
            return this;
        }

        public ShardingRuleBuilder addTables(Map<String, Integer> tables)
        {
            shardingRule.setTables(tables);
            return this;
        }

        public ShardingRuleBuilder addDriverName(String driverName)
        {
            shardingRule.setDriverName(driverName);
            return this;
        }

        public ShardingRule builder()
        {
            return shardingRule;
        }
    }
}
